package com.wu.project.admin.service.impl;

import com.wu.project.admin.component.JsonResult;
import com.wu.project.admin.dao.BusinessDao;
import com.wu.project.admin.entity.*;
import com.wu.project.admin.service.BusinessService;
import com.wu.project.admin.util.CommonResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xuan
 */
@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    BusinessDao businessDao;

    @Override
    public JsonResult getOrder(OrderQueryVO orderQueryVO) {
        Integer offset = CommonResultUtil.Instance.getOffset(orderQueryVO.getPageNum(), orderQueryVO.getPageSize());
        orderQueryVO.setOffset(offset);

        List<OrderDTO> orderList = businessDao.queryOrderList(orderQueryVO);
        Integer count = businessDao.queryOrderListSize(orderQueryVO);
        PageData pageData = new PageData();
        pageData.setPageNum(orderQueryVO.getPageNum());
        pageData.setPageSize(orderQueryVO.getPageSize());
        pageData.setTotal(count);
        pageData.setData(orderList);
        return CommonResultUtil.Instance.success(pageData);
    }

    @Override
    public JsonResult getOrderDetail(String id) {
        return CommonResultUtil.Instance.success(businessDao.queryOrderDetail(id));
    }

    @Override
    public JsonResult getRefundList(RefundVO refundVO) {
        Integer offset = CommonResultUtil.Instance.getOffset(refundVO.getPageNum(), refundVO.getPageSize());
        refundVO.setOffset(offset);

        List<RefundDTO> refundList = businessDao.queryRefundList(refundVO);
        Integer integer = businessDao.queryRefundSize(refundVO);
        PageData<List<RefundDTO>> pageData = new PageData<>();
        pageData.setPageNum(refundVO.getPageNum());
        pageData.setPageSize(refundVO.getPageSize());
        pageData.setTotal(integer);
        pageData.setData(refundList);
        return CommonResultUtil.Instance.success(pageData);
    }
}
